package com.icecold.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class HtmlUtil {

    /**
     * url不可中文
     * 将img标签中的src进行二次包装
     * @param content 内容
     * @param replaceHttp 需要在src中加入的域名
     * @return
     */
    public static String repairContent(String content,String replaceHttp){
        String patternStr="<img\\s*([^>]*)\\s*src=\\\"(.*?)\\\"\\s*([^>]*)>";
        Pattern pattern = Pattern.compile(patternStr,Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(content);
        String result = content;
        while(matcher.find()) {
            String src = matcher.group(2);
            System.out.println("pattern string:"+src);
            String replaceSrc = src;

            if(!src.startsWith("http://")&&!src.startsWith("https://")){
                replaceSrc = replaceHttp + replaceSrc;
            }
            result = result.replace(src,replaceSrc);
        }
        System.out.println(" content == " +content);
        System.out.println(" result == " + result);
        return result;
    }

    public static void main(String[] args) {

        String content = "<!--HTML--><p>&nbsp;<strong> 1、扫描设备上的二维码下载app。</strong></p><p><strong>&nbsp;</strong></p><p><strong>&nbsp;2、设备通过网线连接到光猫或者路由器的网口。登录光猫超级账号，下面一般是光猫自带密码，如果不对请联系当地装维。</strong></p><p><strong>&nbsp;</strong></p><p><strong>&nbsp;3、光猫管理地址<br/></strong></p><p><strong>&nbsp; &nbsp; &nbsp; &nbsp;3.1、默认是<span style=\"color: rgb(255, 0, 0);\">192.168.1.1</span>或者<span style=\"color: rgb(255, 0, 0);\">192.168.0.1</span>（具体看光猫背面信息）接入光猫的wifi或者用网线接入LAN口，自动获取IP地址，打开浏览器，输入http://<span style=\"color: rgb(255, 0, 0);\">192.168.1.1</span><span style=\"color: rgb(255, 0, 0);\"></span></strong></p><p><strong>&nbsp; &nbsp; &nbsp; 3.2、使用超级用户账号密码登录，不同型号和不同地区可能不一样，可以百度查询或者联系服务提供商&nbsp;</strong></p><p><strong>&nbsp; &nbsp; &nbsp; &nbsp; 电信超级账号：telecomadmin&nbsp;<strong style=\"text-wrap: wrap;\">&nbsp;&nbsp; 密码：nE7jA%5m</strong></strong></p><p><strong>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</strong><strong>移动超级账号：CMCCAdmin&nbsp;<strong>&nbsp; &nbsp; &nbsp; 密码：aDm8H%MdA</strong></strong></p><p><strong>&nbsp; &nbsp; &nbsp; &nbsp;</strong><strong>联通超级账号：CUAdmin&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</strong><strong>密码：CUAdmin</strong></p><p><br/></p><p style=\"text-wrap: wrap;\"><strong>4、修改网络类型<br/></strong></p><p><strong>&nbsp;4.1 如果盒子连接的是光猫，进入光猫，应用</strong></p><p><img src=\"/js/userfiles/system/images/20241119/123213_$1732013339487080496.png\" title=\"123213_$1732013339487080496.png\" alt=\"123213.png\"/></p><p><strong>&nbsp;4.2&nbsp;如果盒子连接的是路由器，光猫拨号</strong></p><p><br/></p>";

        String replaceHttp = "http://47.99.214.52:8880";
        int size = 500;
        String result = repairContent(content, replaceHttp);
        System.out.println(result);
    }

}
